<?php
namespace app\api\controller;
use think\Controller;
use think\Request;
use think\Db;

class Cxyun extends Controller{
    public function recordadd(){
        $path=dir(getcwd())->path.'/pay/'.date('Ymd')."/cxyunrecord";
        if (! file_exists ( $path )) {
            mkdir ( "$path", 0777, true );
        }
        $address = $path."/".date('His').rand(100000,999999).'.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);
       // echo "进出记录推送";
        return json(["status"=>1,"message"=>""]);
    }
    
    public function pay(){
        //file_get_contents("php://input");
        $path=dir(getcwd())->path.'/pay/'.date('Ymd')."/cxyunpay";
        //$path=dir(getcwd())->path.'/pay/cxyunpay/'.date('Ymd');
        if (! file_exists ( $path )) {
            mkdir ( "$path", 0777, true );
        }
        $address = $path."/".date('His').rand(100000,999999).'.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);
        echo "进出记录推送";
    }
    public function payrecord(){
        //file_get_contents("php://input");
        $path=dir(getcwd())->path.'/pay/'.date('Ymd')."/cxyunpayrecord";
        //$path=dir(getcwd())->path.'/pay/cxyunpay/'.date('Ymd');
        if (! file_exists ( $path )) {
            mkdir ( "$path", 0777, true );
        }
        $address = $path."/".date('His').rand(100000,999999).'.txt';
        file_put_contents($address,file_get_contents("php://input"),FILE_APPEND);
        
        return json(["status"=>1,"message"=>""]);
    }
    
     public function test2(){
        $path=dir(getcwd())->path.'/pay/20240111/cxyunrecord';//cxyunpay/
        $address = $path."/200209219708.txt";
        $con=file_get_contents($address);
        $data=json_decode($con,true);
        $info["parkingId"]=$data["park_id"];
        $info["parkingNume"]=$data["park_name"];
        $info["recordId"]=$data["record_id"];
        $info["plateNumber"]=$data["plate_number"];
        //查询是否四月租车或福利车
        $carInfo=Db::table("cxyun_car")
                ->where("parkingId",$info["parkingId"])
                ->where("parkingNume",$info["parkingNume"])
                ->find();
                
        $info["car_id"]=$carInfo["id"];
        $info["carType"]=$carInfo["carType"];
        if(empty($carInfo)){
            return json(["status"=>1,"message"=>""]);
        }
        //
        $recordInfo=Db::table("cxyun_car")
                ->where("recordId",$info["recordId"])
                ->where("recordId",$info["recordId"])
                ->find();
        //入场
        if($data["is_exit"]){
           $info["parkingId"]=$data["entrancegate_id"];
        }else{
            //出场
        }
        
        //cxyun_entry_exit_record
        echo "<pre>";
        var_dump($data);
         
     }
     public function test3(){
        $path=dir(getcwd())->path.'/pay/20240111/cxyunrecord';//cxyunpay/
        $address = $path."/200538112011.txt";
        $con=file_get_contents($address);
        $data=json_decode($con,true);
        $info["park_id"]=$data["park_id"];
        $info["parkingNume"]=$data["park_name"];
        $info["recordId"]=$data["record_id"];
        $info["plateNumber"]=$data["plate_number"];
        $info["entranceTime"]=$data["entrance_time"];
        //入场
        if($data["is_exit"]){
            
        }else{
            //出场
        }
        
        //cxyun_entry_exit_record
        echo "<pre>";
        var_dump($data);
         
     }
    public function test(){
        $path=dir(getcwd())->path.'/pay/cxyunpay/20240109';
        $address = $path."/210344674787.txt";
        $con=file_get_contents($address);
        $data=json_decode($con,true);
        $info["parkingId"]=$data["parkId"];
        $info["plateNumber"]=$data["carNo"];
        $info["recordId"]=$data["onlyCode"];
        $info["amount"]=$data["amount"];
        $info["cartypeName"]=$data["carType"];
        $info["carmodelName"]=$data["carSize"];
        $info["inLaneCode"]=$data["inLaneCode"];
        $info["outLaneCode"]=$data["outLaneCode"];
        var_dump($data);
        //改订单是否支付
        $res=Db::table("cxyun_pay_bill")->where("parkingId",$info["parkingId"])->where("recordId",$info["recordId"])->find();
        var_dump($res);
        if(empty($res)){
            //查询是否是月租车
            $monthlyCar=Db::table("cxyun_car")
            ->where("parkingId",$info["parkingId"])
            ->where("plateNumber",$info["plateNumber"])
            ->find();
            if(!empty($monthlyCar)){
                //扣除房屋月租车金额
            }
            return "333";
        }else{
            return json(["status"=>1,"message"=>"成功"]);;
        }
        //$info[""]
        var_dump($data);
    }
}